﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;

public partial class Manager_Product_ProductComment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminUserID"] == null)
        {
            Response.Write("<script language=javascript>alert('Time is out.');window.open('../Default.aspx','_top');</script>");
            return;
        }
        if (!IsPostBack)
        {
            BinData();
        }
    }



    private void BinData()
    {
        DataTable dtD = new DataTable();
        clsWebShop cls = new clsWebShop();
        PccMsg msg = new PccMsg();
        msg.CreateFirstNode("PDID", cls.killSQLInjection(Request.QueryString["PDID"]));
        msg.CreateFirstNode("CmPD_CusName",txtName.Text.Trim());
        msg.CreateFirstNode("CmPD_Title", txtTitle.Text.Trim());
        msg.CreateFirstNode("CmPD_Content",txtContent.Text.Trim());

        dtD = cls.Get_Product_CommentByCondition(msg.GetXmlStr).Tables[0];
        grv_Master.DataSource = dtD;
        grv_Master.DataBind();
        
    }
    
  
    protected void Grv_Product_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.className='cursorOverGrid'");
            if (e.Row.RowIndex % 2 == 0)
                e.Row.Attributes.Add("onmouseout", "this.className='gvRowStyle'");
            else
                e.Row.Attributes.Add("onmouseout", "this.className='gvAlternatingRowStyle'");
        }



    }

    protected void grv_Master_RowCreated1(object sender, GridViewRowEventArgs e)
    {
        for (int i = 0; i < grv_Master.Rows.Count - 1; i++)
        {
            System.Web.UI.WebControls.WebControl myControl = grv_Master.Rows[i].Cells[0];
            myControl.Attributes.Add("onclick", "if(confirm('Delete???')) return true; return false;");
        }

    }

    protected void grv_Master_RowDeleting1(object sender, GridViewDeleteEventArgs e)
    {
        clsWebShop cls = new clsWebShop();
        PccMsg msg = new PccMsg();
       string CmPD_ID=grv_Master.DataKeys[e.RowIndex].Value.ToString();

       cls.UpdateData("delete from Product_Comment Where CmPD_ID=" + CmPD_ID + "");
        ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('Dữ liệu đã cập nhật thành công')</script>");
        BinData();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BinData();
    }
    protected void grv_Master_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grv_Master.PageIndex = e.NewPageIndex;
        BinData();
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        ReturnPage();
    }
    private void ReturnPage()
    {
        Response.Redirect("Product.aspx?KindNo=" + Request.QueryString["KindNo"] + "&CodeID=" + Request.QueryString["CodeID"] + "&sTopicID=" + Request.QueryString["sTopicID"] + "&sCatID=" + Request.QueryString["sCatID"] + "");
    }
}
